<template>
  <div>
    <el-container class="box">
      <el-aside width="200px">
        <el-row class="tac">
          <el-col>
            <!--  default-active    当前激活的菜单
                    background-color  背景颜色
                    text-color        字体颜色
                    active-text-color 当前激活菜单的文字颜色
                    unique-opened     是否只保持一个子菜单的展开
              -->
            <el-menu
              default-active="1-1"
              class="el-menu-vertical-demo"
              background-color="#ff6141"
              text-color="#fff"
              active-text-color="#ffd04b"
              unique-opened
              router
            >
              <el-menu-item index="/">
                <i class="el-icon-warning-outline"></i>
                <span slot="title">首页</span>
              </el-menu-item>

              <!-- <el-submenu index="1">
                <template slot="title">
                  <i class="el-icon-setting"></i>
                  <span>系统设置</span>
                </template>
                <el-menu-item index="menu">菜单管理</el-menu-item>
                <el-menu-item index="role">角色管理</el-menu-item>
                <el-menu-item index="manage">管理员管理</el-menu-item>
              </el-submenu> -->

              <!-- <el-submenu index="2">
                <template slot="title">
                  <i class="el-icon-goods"></i>
                  <span>商城管理</span>
                </template>
                <el-menu-item index="cate">商品分类</el-menu-item>
                <el-menu-item index="specs">商品规格</el-menu-item>
                <el-menu-item index="goods">商品管理</el-menu-item>
                <el-menu-item index="member">会员管理</el-menu-item>
                <el-menu-item index="banner">轮播图管理</el-menu-item>
                <el-menu-item index="seckill">秒杀活动</el-menu-item>
              </el-submenu> -->

              <div v-for="item in user.menus" :key="item.id">
                <!-- 目录 -->
                <el-submenu :index="item.id + ''" v-if="item.children">
                  <template slot="title">
                    <i :class="item.icon"></i>
                    <span>{{ item.title }}</span>
                  </template>
                  <el-menu-item
                    v-for="i in item.children"
                    :key="i.id"
                    :index="i.url"
                    >{{ i.title }}</el-menu-item
                  >
                </el-submenu>

                <!-- 菜单 -->
                <el-menu-item :index="item.url" v-else>{{
                  item.title
                }}</el-menu-item>
              </div>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-container>
        <el-header>
          <p class="user">用户名：{{ user.username }}</p>
          <el-button @click="goOut()" class="btn">退 出</el-button>
        </el-header>
        <el-main>
          <!-- 面包屑 -->
          <el-breadcrumb
            separator-class="el-icon-arrow-right"
            class="breadcrumbBox"
          >
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
          <!-- 路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { successAlert } from "../../util/alert";
export default {
  computed: {
    ...mapGetters({
      user: "user",
    }),
  },
  methods: {
    ...mapActions({
      reqChangeUser: "reqChangeUser",
    }),
    // 退出
    goOut() {
      // 清空状态层
      this.reqChangeUser({});
      // 即将跳转的提示
      successAlert("退出成功");
      // 跳转到登录页
      this.$router.push("/login");
    },
  },
};
</script>

<style lang="less">
@import url("../../less/index.less");
.box {
  width: 100vw;
  height: 100vh;
}
.el-header {
  background-color: @color2;
  color: #333;
}
.el-aside {
  background-color: @color1;
  color: #333;
}
.el-main {
  background-color: #e9eef3;
  color: #333;
}
.breadcrumbBox {
  margin-bottom: 20px;
}
.el-header .user {
  float: right;
  font-weight: bold;
  margin-right: 10%;
  margin-top: 2.5%;
}
.el-header .el-button {
  margin-left: 91%;
  margin-top: 1%;
  display: block;
  transition: 0.5s ease;
}
.el-header .el-button:hover {
  color: #fff;
  background: #ff6141;
}
</style>


